package com.stadium.controller;

import java.util.List;
import java.util.UUID;

import com.stadium.common.BaseResponse;
import com.stadium.common.exception.RRException;
import com.stadium.dto.SysAdminUserDto;
import com.stadium.service.SysAdminUserSV;
import com.stadium.service.SysUserSV;
import com.stadium.vo.SysAdminUserVo;
import com.stadium.vo.searchVo.SysAdminUserSearchVo;
import io.micrometer.core.instrument.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 赛事管理员表
 *
 * @author wsl
 * @email
 * @date 2021-05-08 17:45:58
 */
@RestController
@RequestMapping("/api/sysadminuser")
@Api(tags = "赛事管理员表")
public class SysAdminUserCL{
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private SysAdminUserSV sysAdminUserSV;


    @ApiOperation(value = "保存或修改")
    @PostMapping(value = "/v1/save")
    public BaseResponse save(@Validated SysAdminUserVo sysAdminUserVo) {
        try {
            if (sysAdminUserVo.getId() == null ||sysAdminUserVo.getId() == ""){
                    sysAdminUserSV.save(sysAdminUserVo);
            }else{
                    sysAdminUserSV.update(sysAdminUserVo);
            }
            return BaseResponse.ok();

        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/v1/delete")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value="id")})
    public BaseResponse delete(@RequestParam(name = "id", required = true)String id) {
        try {
            sysAdminUserSV.delete(id);
            return BaseResponse.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "审核")
    @PostMapping(value = "/v1/audit")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value="id"),
            @ApiImplicitParam(name="审核状态（2：未审核 1：审核通过 0：审核未通过",value="审核状态（2：未审核 1：审核通过 0：审核未通过")})
    public BaseResponse audit(@RequestParam(name = "id", required = true)String id,
                              @RequestParam(name = "status", required = true)String status) {
        try {
            sysAdminUserSV.audit(id,status);
            return BaseResponse.ok();
        }catch (RRException e) {
            e.printStackTrace();
            return BaseResponse.error("该用户不存在");
        }
        catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "获得未审核列表")
    @GetMapping(value = "/v1/queryNoAudit")
    public BaseResponse<List<SysAdminUserDto>> queryNoAudit(@Validated SysAdminUserSearchVo searchVo) {
        try {
            if (StringUtils.isNotEmpty(searchVo.getSearchValue())) {
                searchVo.setSearchValue("%" + searchVo.getSearchValue() + "%");
            }
            searchVo.setAuditStatus("0");
            List<SysAdminUserDto> queryList = sysAdminUserSV.query(searchVo);
            int total = sysAdminUserSV.getCount(searchVo);
            return BaseResponse.ok(queryList, total);
        } catch (Exception e) {
            logger.error("日志失败！", e);
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "获得已审核列表")
    @GetMapping(value = "/v1/queryAudit")
    public BaseResponse<List<SysAdminUserDto>> queryAudit(@Validated SysAdminUserSearchVo searchVo) {
        try {
            if (StringUtils.isNotEmpty(searchVo.getSearchValue())) {
                searchVo.setSearchValue("%" + searchVo.getSearchValue() + "%");
            }
            searchVo.setAuditStatus("1");
            List<SysAdminUserDto> queryList = sysAdminUserSV.query(searchVo);
            int total = sysAdminUserSV.getCount(searchVo);
            return BaseResponse.ok(queryList, total);
        } catch (Exception e) {
            logger.error("日志失败！", e);
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "获得详情", notes = "获得详情")
    @GetMapping(value = "/v1/get")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value="id")})
    public BaseResponse<SysAdminUserDto> get(@RequestParam(name = "id", required = true)String id) {
        try {
                SysAdminUserDto queryData = sysAdminUserSV.get(id);
            return BaseResponse.ok(queryData);
        } catch (Exception e) {
            logger.error("日志失败！", e);
            return BaseResponse.error();
        }
    }
}
